
import { _decorator, Component,  Sprite, SpriteFrame, UITransform } from 'cc';
import { TILE_TYPE_ENUM } from '../../Enums';
const { ccclass, property } = _decorator;

// 地砖的长宽
export const TILE_HEIGHT = 55
export const TILE_WIDTH = 55

@ccclass('TileManager')
export class TileManager extends Component {
  type:TILE_TYPE_ENUM
  // 地砖的属性，可走的
  moveable:boolean
  // 地砖的属性，可在上方旋转的
  turnable:boolean
  init(type:TILE_TYPE_ENUM,spriteFrame: SpriteFrame, i:number, j:number) {
    this.type = type
    if (
      this.type === TILE_TYPE_ENUM.FLOOR
    ) {
      this.moveable = true
      this.turnable = true
    } else if (
      this.type === TILE_TYPE_ENUM.CLIFF_LEFT ||
      this.type === TILE_TYPE_ENUM.CLIFF_RIGHT ||
      this.type === TILE_TYPE_ENUM.CLIFF_CENTER
    ) {
      this.moveable = false
      this.turnable = true
    } else {
      this.moveable = false
      this.turnable = false
    }





    const sprite = this.addComponent(Sprite)
    sprite.spriteFrame = spriteFrame

    // 为图片添加可以缩放大小
    const transform = this.getComponent(UITransform)
    transform.setContentSize(TILE_WIDTH, TILE_HEIGHT)
    // 设置图片位置
    this.node.setPosition(i * TILE_WIDTH, -j * TILE_HEIGHT)
  }
}
